<template>
    <div class="login-container">
      <el-card class="login-box">
        <h2 class="login-title">系统登录</h2>
        <el-form ref="loginForm" :model="form" @keyup.enter="handleLogin">
          <el-form-item>
            <el-input
              v-model="form.username"
              placeholder="请输入用户名"
              prefix-icon="User"
            />
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="form.password"
              type="password"
              placeholder="请输入密码"
              prefix-icon="Lock"
              show-password
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              @click="handleLogin"
              :loading="loading"
              style="width: 100%"
            >
              登录
            </el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  import { ElMessage } from 'element-plus'
  import axios from 'axios'
  
  const router = useRouter()
  const form = ref({ username: '', password: '' })
  
  const handleLogin = async () => {
    const res = await sxios.get('http://localhost:8080/login',{
      params:{
        username: form.value.username,
        password: form.value.password
      }
    })
    if (res.data !== 'error'){
      localStorage.setItem('token',res.data)
      router.push('/page1')
    } else {
      ElMessage.error('登录失败')
    }

  }
  </script>
  
  <style scoped>
  .login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  }
  .login-box {
    width: 400px;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
  }
  .login-title {
    text-align: center;
    margin-bottom: 30px;
    color: #333;
  }
  </style>